package com.hdax.dm.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.entity.order.Order;
import com.hdax.dm.order.dto.QueryOrderListDto;
import com.hdax.dm.order.mappers.OrderMapper;
import com.hdax.dm.order.service.QueryOrderListService;
import com.hdax.dm.utils.CommonResponse;
import com.hdax.dm.utils.ResponseUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 个人中心的实现类
 */
@Service
public class QueryOrderListServiceImpl extends ServiceImpl<OrderMapper, Order> implements QueryOrderListService{

    @Override
    public CommonResponse queryOrderList(Map<String, String> param) {

            List<Order> orders = baseMapper.likeOrder(param.get("orderType"),param.get("orderTime"),param.get("keyword"));
            List<QueryOrderListDto> orderListDtos = new ArrayList<>();
            orders.forEach(order -> {
                QueryOrderListDto orderListDto = new QueryOrderListDto();
                BeanUtils.copyProperties(order,orderListDto);
                orderListDto.setNum(order.getTotalCount());
                orderListDto.setSellTime(order.getCreatedTime());
                orderListDtos.add(orderListDto);
            });

        return ResponseUtil.returnSuccess(orderListDtos);
    }
}
